home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug172 / out2.c < prev    next >
C/C++ Source or Header  |  1986-02-05  |  5KB  |  145 lines

  1. /*
  2.   HEADER: CUG     nnn.nn;
  3.   TITLE:     LEX - A Lexical Analyser Generator
  4.   VERSION:     1.0 for IBM-PC
  5.   DATE:      Jan 30, 1985
  6.   DESCRIPTION:     A Lexical Analyser Generator. From UNIX
  7.   KEYWORDS:     Lexical Analyser Generator YACC C PREP
  8.   SYSTEM:     IBM-PC and Compatiables
  9.   FILENAME:      OUT2.C
  10.   WARNINGS:     This program is not for the casual user. It will
  11.          be useful primarily to expert developers.
  12.   CRC:         N/A
  13.   SEE-ALSO:     YACC and PREP
  14.   AUTHORS:     Scott Guthery 11100 leafwood lane Austin, TX 78750
  15.   COMPILERS:     DESMET-C
  16.   REFERENCES:     UNIX Systems Manuals
  17. */
  18. /*
  19.  * out2.c  --     Some of Lex's output routines for overlaying, moved
  20.  *                here from the original out.c as part of size reduction
  21.  *                effort.
  22.  *      Bob Denny
  23.  *      03-Dec-80
  24.  * More...
  25.  *      Bob Denny
  26.  *      29-May-81       RSX overlaying
  27.  *      19-Mar-82 Bob Denny -- New compiler and library
  28.  *      28-Aug-82 Bob Denny -- Change output format for readability. I know
  29.  *                              you UNIX hackers are not going to like this
  30.  *                              one.  Add code to generate llstin() per
  31.  *                              setting of "-s" switch.  Fix cclprint() to
  32.  *                              put 16 "characters" on a line. Clean up
  33.  *                              nfaprint().
  34.  *      29-Aug-82 Bob Denny -- Move chprint to root. Add llstin() to
  35.  *                              default lexin to stdin for standard I/O
  36.  *                              and no-op for stand-alone I/O.  Allows
  37.  *                              sdtio-specific code to be removed from
  38.  *                              yylex().
  39.  *      31-Aug-82 Bob Denny -- Add lexswitch( ...) to llstin so table
  40.  *                              name selected by -t switch is automatically
  41.  *                              switched-to at yylex() startup time.  Removed
  42.  *                              hard reference to "lextab" from yylex();
  43.  *      30-Oct-82 Bob Denny -- Remove lexswitch() from llstin(). Made it
  44.  *                              impossible to do a real lexswitch()! (dumb.)
  45.  *                              Default the table by statically initializing
  46.  *                              it to NULL and doing the lexswitch only if
  47.  *                              _tabp is NULL.
  48.  *        20-Nov-83 Scott Guthery -- Adapt for IBM PC & DeSmet C
  49.  */
  50.  
  51. #include <stdio.h>
  52. #include "lexlex.h"
  53.  
  54. extern int yyline;
  55.  
  56. #ifdef DEBUG
  57.  
  58. nfaprint(np, base)
  59. register struct nfa *np;
  60. struct nfa *base;
  61. {
  62.         register i;
  63.  
  64.         if (np->n_flag&NPRT)
  65.                 return;
  66.         np->n_flag |= NPRT;
  67.         fprintf(lexlog, "state %d\n", np-base);
  68.         switch (np->n_char) {
  69.         case EPSILON:
  70.                 for (i = 0; i < 2; i++)
  71.                         if (np->n_succ[i])
  72.                                 fprintf(lexlog, "\tepsilon  %d\n", np->n_succ[i]-base);
  73.                 break;
  74.         case FIN:
  75.                 fprintf(lexlog, "\tfinal state\n");
  76.                 break;
  77.         case CCL:
  78.                 fprintf(lexlog, "\t[");
  79.                 cclprint(np->n_ccl);
  80.                 fprintf(lexlog, "]  %d\n", np->n_succ[0]-base);
  81.  
  82.                 break;
  83.         default:
  84.                 putc('\t', lexlog);
  85.                 chprint(np->n_char);
  86.                 fprintf(lexlog, "  %d\n", np->n_succ[0]-base);
  87.                 break;
  88.         }
  89.         putc('\n', lexlog);
  90.         if (np->n_succ[0])
  91.                 nfaprint(np->n_succ[0], base);
  92.         if (np->n_succ[1])
  93.                 nfaprint(np->n_succ[1], base);
  94. }
  95.  
  96. cclprint(cp)
  97. register char *cp;
  98. {
  99.         register i;
  100.         register nc;
  101.  
  102.         nc = 0;
  103.         for (i = 0; i < NCHARS; i++)
  104.                 {
  105.                 if (cp[i / NBPC] & (1 << (i % NBPC)))
  106.                         nc += chprint(i);
  107.                 if(nc >= 64)
  108.                         {
  109.                         nc = 0;
  110.                         fprintf(lexlog, "\n\t ");
  111.                         }
  112.                 }
  113. }
  114.  
  115. #endif
  116.  
  117. llactr()
  118. {
  119.         /*
  120.          * Prior to generating the action routine, create
  121.          * the llstin() routine, which initializes yylex(),
  122.          * per the setting of the "-s" switch.  All hardwired
  123.          * variables have now been removed from yylex(). This
  124.          * allows analyzers to be independent of the standard
  125.          * I/O library and the table name.
  126.          */
  127.         fprintf(llout, "_A%s(__na__)\t\t/* Action routine */\n   {\n", tabname);
  128. }
  129.  
  130.  
  131. newcase(i)
  132. {
  133.         static int putsw;
  134.  
  135.         if (!putsw++)
  136.                 fprintf(llout, "   switch (__na__)\n      {\n");
  137.         fprintf(llout, "\n      case %d:\n", i);
  138.         setline();
  139. }
  140.  
  141. setline()
  142. {
  143.         fprintf(llout, "\n#line %d\n", yyline);
  144. }
  145.